<template>
  <div>
    <el-form  inline size="mini">
      <el-form-item label="类加载器">
        <el-select v-model="serializerParam.classloader" style="width: 150px" @change="change" >
          <el-option v-for="classloader in classloaders" :key="classloader" :value="classloader"
                     :label="classloader"/>
        </el-select>
      </el-form-item>
      <el-form-item label="key">
        <el-select v-model="serializerParam.keySerializer" style="width: 100px;" @change="change">
          <el-option v-for="serializer in serializers" :key="serializer" :value="serializer" :label="serializer"/>
        </el-select>
      </el-form-item>
      <el-form-item label="value">
        <el-select v-model="serializerParam.value" style="width: 100px;" @change="change">
          <el-option v-for="serializer in serializers" :key="serializer" :value="serializer" :label="serializer"/>
        </el-select>
      </el-form-item>
      <el-form-item label="hashKey">
        <el-select v-model="serializerParam.hashKey" style="width: 100px;" @change="change">
          <el-option v-for="serializer in serializers" :key="serializer" :value="serializer" :label="serializer"/>
        </el-select>
      </el-form-item>
      <el-form-item label="hashValue">
        <el-select v-model="serializerParam.hashValue" style="width: 100px;" @change="change">
          <el-option v-for="serializer in serializers" :key="serializer" :value="serializer" :label="serializer"/>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="text"   size="mini" @click="localStorageConfig" > <i class="fa fa-floppy-o" aria-hidden="true"></i></el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import core from "@/api/core";

export default {
  name: "RedisSerializerChose",
  props:{
    serializerParam: Object
  },
  model: {
    prop: 'serializerParam',
    event: 'serializerParamChange'
  },
  data(){
    return {
      classloaders: [],
      serializers: []
    }
  },
  methods:{
    localStorageConfig() {
      this.$storeLocal.set('redis.config', this.serializerParam)
      this.$message({type:'success',message:'个人配置保存成功,下次直接使用此配置'});
    },
    change(){
      this.$emit('serializerParamChange',this.serializerParam)
    }
  },
  mounted() {
    // 加载所有的序列化工具和类加载器工具
    core.classloaders().then(res => {
      this.classloaders = res.data
    })
    core.serializers().then(res => {
      this.serializers = res.data
    })

    // 加载本地保存的配置,如果之前有保存的话
    let config = this.$storeLocal.get('redis.config')
    if (config) {
      Object.assign(this.serializerParam, config);
      this.$emit('serializerParamChange',this.serializerParam)
    }
  }
}
</script>

<style scoped>

</style>
